package com.genITeam.ria.dao;
import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.Session;
import org.hibernate.criterion.Expression;

import com.genITeam.ria.exception.NGFException;
import com.genITeam.ria.vo.ModeratorRequest;
import com.genITeam.ria.vo.Posts;
public class UserRequestDAO {

	Logger logger = Logger.getLogger(TheadPostDAO.class);

	public List getUserRequest(Session session) throws NGFException{
		ModeratorRequest moderatorRequestVo = null;
		List reqList = null;
		try {	
			logger.info("Start getModeratorRequest");	
//			System.out.println("in dao "  + id ); 

			reqList = (List) session.createCriteria(ModeratorRequest.class).add(Expression.eq("status", new Character('n'))).list();
		     
		} catch (Exception e) {
			System.out.println(e.getMessage()) ;
			logger.error(e.toString());
			throw new NGFException(e.getMessage());

		}

		return reqList;
		
	}
	
	public void approveRequest(ModeratorRequest moderatorRequestVo, Session session) throws NGFException{
		try {
			
			logger.info("start approve request");
			session.saveOrUpdate(moderatorRequestVo);
		} catch (Exception e) {
			logger.error("Exception =" + e.toString());
			throw new NGFException(e.getMessage());

		}
		
	}
	
	public void submitUserRequest(ModeratorRequest moderatorRequestVo, Session session) throws NGFException{
		
		try {
			System.out.println("in submit user request DAO member id = "+ moderatorRequestVo.getMember().getId());
			
			logger.info("start submit user request");
			session.saveOrUpdate(moderatorRequestVo);
		} catch (Exception e) {
			logger.error("Exception =" + e.toString());
			throw new NGFException(e.getMessage());

		}
	}
	
	public ModeratorRequest getRecord(int id, Session session){
		ModeratorRequest moderatorRequestVo = null;
		moderatorRequestVo= (ModeratorRequest) session.createCriteria(ModeratorRequest.class).add(Expression.eq("id", new Integer(id))).uniqueResult() ;
		       
		return moderatorRequestVo;
		
	}
}
